package com.hnit.controller;

import com.hnit.service.HelloClient;
import com.hnit.service.IdGeneratorClient;
import com.hnit.web.bean.ResponseResult;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequiredArgsConstructor  //构造器注入
public class ConsumerController {
    //因为是final 所以要使用构造器完成注入，构造器完成注入与@Autowried注入不同同时使用
    //构造器注入相对于@Autowired注入更简洁，推荐使用构造器注入
    private final HelloClient helloClient;
    //自动注入
//    @Autowired
//    private HelloClient helloClient;
    @Autowired
    private IdGeneratorClient idGeneratorClient;

//    @GetMapping("/test")
//    public Map<String, Object> test() {
//        ResponseResult hello = helloClient.getHello();
//        ResponseResult id = idGeneratorClient.getId();
//
//        Map<String, Object> result = new HashMap<>();
//        result.put("code", 1);
//        result.put("msg", "");
//        result.put("data", hello + " " + id);
//
//        return result;
//    }

    @GetMapping("/test")
    public ResponseResult test() {
        ResponseResult responseResult = helloClient.getHello();           // 调用 hello-service
        ResponseResult responseResult1= idGeneratorClient.getId();                     // 调用 id-generator
        String result = responseResult.getData().toString() + "   " + responseResult1.getData().toString();
        return ResponseResult.builder()
                .code(1)
                .msg("")
                .data(result)
                .build();
    }
}


